package edu.ucsd.cse135.gas.action.reviewer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.bean.reviewer.ReviewBean;
import edu.ucsd.cse135.gas.logic.reviewer.ReviewerFunctions;
import edu.ucsd.cse135.gas.resources.Constants;

public class StoreCompletionAction extends Action {

	public StoreCompletionAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
		ReviewBean decision = (ReviewBean)form;
		
		ReviewBean grading = (ReviewBean)request.getSession().getAttribute("grading"); 
		
		if(decision.getDecision().equals("Accepted"))
		{
			ReviewerFunctions.storeCompletion("Accepted", decision.getApplicant(), grading.getGrade(), grading.getComment(), grading.getReviewer());
		}
		else if(decision.getDecision().equals("Rejected"))
		{
			ReviewerFunctions.storeCompletion("Rejected", decision.getApplicant(), grading.getGrade(), grading.getComment(), grading.getReviewer());
		}
		else
		{
			ReviewerFunctions.storeCompletion("Pending", decision.getApplicant(), grading.getGrade(), grading.getComment(), grading.getReviewer());
		}
		
		return mapping.findForward(Constants.SUCCESS);
		
	}
	
}
